﻿@{
    Layout = null;
    ViewBag.Title = "文件导入弹窗口";
}
<script type="text/javascript">
    function dialogRefresh(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            $("#pagerForm", navTab.getCurrentPanel()).submit();
            $.pdialog.closeCurrent();
        }
    }
</script>
<form id="impotExcelForm" action="@(ViewBag.Url)" method="post" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogRefresh)">
<input type="hidden" id="Section" name="Section" value="@(ViewBag.Section)" />
<div class="pageFormContent" layouth="58">
    <table class="tab01 tabNo">
        <tr>
            <td class="td1" style="width: 25%;">
                日期：
            </td>
            <td>
                <input type="text" name="report_date" id="report_date" class="date required input02" format="yyyy-MM" />
            </td>
        </tr>
        <tr>
            <td class="td1">
                附件：
            </td>
            <td>
                <input type="file" name="filePath" id="filePath" class="required" size="30" onchange="onfileChange(event)" />
            </td>
        </tr>
    </table>
</div>
<div class="formBar">
    <ul>
        <li>
            <button type="button" id="btnImport" class="btn btn-sm">
                导入</button>
        </li>
        <li>
            <button type="button" class="close btn btn-default btn-sm">
                取消</button>
        </li>
    </ul>
</div>
</form>
<script type="text/javascript">

    var uFiles;
    var date;
    $(document).ready(function () {
        $("#btnImport").bind("click", function () {
            var ajaxbg = $("#background,#progressBar");

            if (uFiles && uFiles != null) {
                ajaxbg.show();
                recursiveFiles(uFiles[0]);
            } else {
                var fileLocalPath = $("#filePath").val();
                var reportdate = $("#report_date").val();
                if (reportdate == "") {
                    alertMsg.warn('请选择日期！');
                    return;
                }
                if (fileLocalPath == "") {
                    alertMsg.warn('请选择Excel文件上传！');
                } else {
                    alertMsg.warn('请使用IE9以上浏览器,导入文件!');
                }
            }
        });

    });

    function onfileChange(e) {
        uFiles = e.target.files;
    }


    function recursiveFiles(file) {
        var reader = new FileReader();
        reader.onload = function (event) {
            var url = $('#impotExcelForm').attr('action');
            var Section = $("#Section").val();
            var Date = $("#report_date").val();

            $.ajax(
            { url: url,
                data: { datas: new Int8Array(event.target.result), Section: Section, Date: Date },
                success: function (res) {
                    uFiles = null;
                    dialogRefresh(res);
                },
                error: function (res) {
                    uFiles = null;
                },
                async: false,
                type: "post"
            });
        };
        reader.readAsArrayBuffer(file);
    }
</script>
